package com.zmn.plat.services.impl.channel.bail;


import com.zmn.plat.model.entity.channel.bail.ChannelBail;
import com.zmn.plat.model.entity.channel.bail.ChannelBailQuery;
import com.zmn.plat.persistence.interfaces.channel.bail.ChannelBailDAO;
import com.zmn.plat.services.interfaces.channel.bail.ChannelBailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 渠道保证金接口实现类
 *
 * @author jiafei
 * @since  2021-06-16 09:51:40
 */
@Slf4j
@Service
public class ChannelBailServiceImpl implements ChannelBailService {

    private static final String TAG = "渠道保证金基础服务接口";

    @Resource
    private ChannelBailDAO channelBailDAO;

    @Override
    public ChannelBail findById(Integer channelId) {

        if (Objects.isNull(channelId)) {
            log.error("[{}],根据channelId查询数据channelId为null", TAG);
            return null;
        }
        return channelBailDAO.findById(channelId);
    }

    @Override
    public List<ChannelBail> listPageByQuery(ChannelBailQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(channelBailDAO.countByQuery(query));
        return channelBailDAO.listPageByQuery(query);
    }

    @Override
    public List<ChannelBail> listByQuery(ChannelBailQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return channelBailDAO.listByQuery(query);
    }

    @Override
    public Integer countByQuery(ChannelBailQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return channelBailDAO.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ChannelBail ChannelBail) {

        if (Objects.isNull(ChannelBail.getChannelId())) {
            log.error("[{}],根据id修改数据,ChannelBail为null", TAG);
            return null;
        }
        return channelBailDAO.updateByKey(ChannelBail);
    }

    @Override
    public Integer updateBalance(Integer channelId, Integer amount) {

        if (Objects.isNull(channelId)) {
            log.error("[{}],根据channelId修改账户amount为null, channelId:{},amount:{}", TAG, channelId, amount);
            return null;
        }
      return  channelBailDAO.updateBalance(channelId, amount);
    }

    @Override
    public Integer insert(ChannelBail ChannelBail) {

        if (Objects.isNull(ChannelBail)) {
            log.error("[{}],新增数据,ChannelBail为null", TAG);
            return null;
        }
        return channelBailDAO.insert(ChannelBail);
    }

    @Override
    public Integer deleteByKey(Integer channelId) {

        if (Objects.isNull(channelId)){
            log.error("[{}],根据id删除数据,channelId为null", TAG);
            return null;
        }
        return channelBailDAO.deleteByKey(channelId);
    }

}